***************
*** PANEL A ***
***************
clear all 
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_figures"
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/
set scheme s1color

use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

collapse (p20) p20logearnwke=logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate
xtset smsa year  

local controls p20logearnwke(1979) p20logearnwke(1973) p20logearnwke low_skilled hisp manuf
synth p20logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig3a.dta, replace)

use fig3a, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	t2title("20th Percentile Log Weekly Wages") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""'  1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	text(5.2 1990.8 "Panel A") ///
	yscale(range(4.7 5.2)) ///
	ylabel(4.7(.1)5.2) ///
	plotregion(lwidth(none))

graph copy one, replace

*******************
*** PANELS B, C ***
*******************
clear
use $folder/aux_may-org.dta
set matsize 800

keep if age >= 16 & age <= 61
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

gen female = 1 - male
gen yearbin = 1 * (year >= 1972 & year <= 1975) + 2 * (year >= 1976 & year <= 1978) + ///
		3 * (year >= 1980 & year <= 1982) + 4 * (year >= 1983 & year <= 1985) + ///
		5 * (year >= 1986 & year <= 1988) + 6 * (year >= 1989 & year <= 1991)

gen agebin = 1 * (age <= 20) + 2 * (age > 20 & age <= 25) + 3 * (age >25 & age <= 30) + ///
	4 * (age > 30 & age <= 34) + 5 * (age >35 & age <= 40) + 6 * (age > 40 & age <= 45) + ///
	7 * (age > 45 & age <= 50) + 8 * (age > 50 & age <= 55) + 9 * (age > 55) 

tab yearbin, gen(yearbins)
tab agebin, gen(agebins)

reg logearnwke female##yearbins* hisp##yearbins* agebins*##yearbins* black##yearbins*, vce(cluster smsarank)
predict double wage_resid, resid
drop logearnwke
rename wage_resid logearnwke

reg loguearnhre female##yearbins* hisp##yearbins* agebins*##yearbins* black##yearbins*, vce(cluster smsarank)
predict double wage_resid, resid
drop loguearnhre
rename wage_resid loguearnhre

collapse (mean) logearnwke loguearnhre [pw=earnwt], by(year smsarank)
merge 1:1 year smsa using $folder/msa_controls_may-org.dta, nogenerate
xtset smsa year

local controls logearnwke(1973) logearnwke(1978) logearnwke(1979) low_skilled hisp manuf
synth logearnwke `controls', trunit(26) trperiod(1980) nested keep(fig3b.dta, replace)

local controls loguearnhre(1976) low_skilled hisp manuf
synth loguearnhre `controls', trunit(26) trperiod(1980) nested keep(fig3c.dta, replace)

use fig3b, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami")) ///
	subtitle("Regression-Adjusted Log Weekly Wages") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	yscale(range(-.3 .2)) ///
	ylabel(-.3(.1).2) ///
	text(.2 1990.8 "Panel B")  plotregion(lwidth(none))

graph copy two, replace

use fig3c, clear
rename (_time _Y_treated _Y_synthetic) (year miami synthetic)
keep if year != .
twoway (line miami year, lcolor(black) lpattern(solid)) ///
	(line synthetic year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Synthetic Miami") size(small)) ///
	subtitle("Regression-Adjusted Log Hourly Wages") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' ///
	1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	text(.1 1990.8 "Panel C") ///
	ylabel(-.4(.1).1)  plotregion(lwidth(none))
	
graph copy three, replace

***************
*** PANEL D ***
***************
clear
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

keep if smsarank == 26 | smsarank == 21 | smsarank == 2 | smsarank == 33 | smsarank == 14

gen city = 2
replace city = 1 if smsarank == 26

collapse (mean) logearnwke [pw=earnwt], by(year city)
reshape wide logearnwke, i(year) j(city)

rename (logearnwke1 logearnwke2) (logearnwke_mia logearnwke_card)

save fig3d.dta, replace

scalar a = (logearnwke_mia[7] - logearnwke_card[7])/1.8
replace logearnwke_mia = logearnwke_mia - a

twoway (line logearnwke_mia year, lcolor(black) lpattern(solid)) ///
	(line logearnwke_card year, lcolor(black) lpattern(dash)), ///
	xline(1979, lcolor(black) lpattern(dash)) ///
	xtitle("") ///
	ytitle("") ///
	legend(label(1 "Miami") label(2 "Card (1990) Control")) ///
	t2title("Log Weekly Wages, Card (1990) Control") ///
	xlabel(1973 "1973" 1975 "75" 1977 "77" 1979 `""79" "Pre""' 1981 `""81" "Post""' 1983 "83" 1985 "85" 1987 "87" 1989 "89" 1991 "91") ///
	xscale(range(1972 1992)) ///
	yscale(range(5 5.5)) ///
	ylabel(5(.1)5.5) ///
	text(5.5 1990.8 "Panel D") ///
	plotregion(lwidth(none))
	
graph copy four, replace	
	
grc1leg one two three four,	imargin(vsmall) legendfrom(three)
graph export "jhr_fig3.pdf", replace
